<?php
// 本类由系统自动生成，仅供测试用途
class PublicAction extends Action{



    public function index(){
    	$this->display("login");
     }

	public function login(){
		if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			$this->assign('sys_name',c('CMS_NAME'));
			$this->display();
			
		}
		else {
			redirect(PHP_FILE);
		}
	}

	public function logout(){
		if(Session::is_set(C('USER_AUTH_KEY'))){
			//$_SESSION[C('USER_AUTH_KEY')] = "";
			unset($_SESSION[C('USER_AUTH_KEY')]);
			//session_destroy();
			//Session::clear();
			$this->assign('jumpUrl',__URL__.'/login');
			$this->success("注销成功！");
		}else{
			$this->assign('jumpUrl',__URL__.'/login');
			$this->error('已经注销！');
		}
		//$this->forward();
	}


	public function logchek(){
		if($_POST['acc_name'] && $_POST['verify']){

			if($_SESSION['verify'] != md5($_POST['verify'])){
				//echo "3";
				//echo $_SESSION['verify']."</br>";
				//echo md5($_POST['verify']);
				$this->ajaxReturn(__APP__."/public/verify/",'验证码错误',0);
			}
			else{
				
				$map['uname'] = $_POST['acc_name'];
				$map['pwd'] = md5($_POST['pwd']);
				
				$checkUser = M("member")->where($map)->find();
				
				//dump($user->getLastSql());
				
				if(!$checkUser){
					//$this->assign("jumpUrl","__APP__");
					$this->ajaxReturn(__ROOT__."/admin.php/public/verify/","用户名或密码不正确！",0);
				}else{
					
					Session::set(C('USER_AUTH_KEY'),$checkUser['uid']);
					Session::set('admin',$checkUser['uname']);
					$this->ajaxReturn(__ROOT__."/master.php","登录成功",1);
					
				}

			}
		}


	}
	
	public function verify(){
		$type = isset($_GET['type'])?$_GET['type']:'gif'; 
		import("ORG.Util.Image");
	    Image::buildImageVerify(4,1,$type); 
    }


	public function top(){
		if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			
			redirect(PHP_FILE);
			
		}
		else {
			$this->display();
			
		}
		
    }

	public function left(){
		if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			
			redirect(PHP_FILE);
			
		}
		else {
			$this->display();
			
		}
    }

	public function main(){
		if(!isset($_SESSION[C('USER_AUTH_KEY')])){
			redirect(PHP_FILE);
			
		}
		else {
			$this->assign('sys_name',c('CMS_NAME'));
			$this->display();
			
		}

		
	}
}
?>